package com.control.qct.businesssteward.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.activity.ChargeBackActivity;
import com.control.qct.businesssteward.activity.CheckActivity;
import com.control.qct.businesssteward.activity.EverydayAccountActivity;
import com.control.qct.businesssteward.activity.GoodsActivity;
import com.control.qct.businesssteward.activity.OpenOrderActivity;
import com.control.qct.businesssteward.activity.OrderActivity;
import com.control.qct.businesssteward.activity.ReplenishmentActivity;
import com.control.qct.businesssteward.activity.StatementActivity;
import com.control.qct.businesssteward.activity.TakeDeliveryActivity;
import com.control.qct.businesssteward.activity.TheCargoActivity;
import com.control.qct.businesssteward.adapter.HomeAdapter;
import com.control.qct.businesssteward.base.BaseFragment;
import com.control.qct.businesssteward.model.HomeModel;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/23 0023.
 */

public class HomeFragment extends BaseFragment {
    @BindView(R.id.tv_open_order)
    TextView mTvOpenOrder;
    @BindView(R.id.tv_collect_money)
    TextView mTvCollectMoney;
    @BindView(R.id.tv_replenishment)
    TextView mTvReplenishment;
    @BindView(R.id.rv_type)
    RecyclerView mRvType;

    private List<HomeModel> mHomeModels;
    private HomeAdapter mHomeAdapter;
    private String typeName[] = {"商品", "订单", "日结", "盘点", "报表", "会员", "促销", "收货", "调货", "退单", "退换货", "周边库存"};
    private int imageId[] = {R.drawable.icon_shouye_shangpin, R.drawable.icon_shouye_dingdan, R.drawable
            .icon_shouye_rijie, R.drawable.icon_shouye_pandian, R.drawable.icon_shouye_baobiao, R.drawable
            .icon_shouye_kucun, R.drawable.icon_shouye_huiyuan, R.drawable.icon_shouye_cuxiao, R.drawable
            .icon_shouye_shouhuo, R.drawable.icon_shouye_tiaohuo, R.drawable.icon_shouye_tuidan, R.drawable
            .icon_shouye_tuihuanhuo};

    @Override
    protected View initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    @Override
    protected void initView(View view) {
        mHomeModels = new ArrayList<>();
        for (int i = 0; i < typeName.length; i++) {//添加名称和图标
            mHomeModels.add(new HomeModel(imageId[i], typeName[i]));
        }
        mHomeAdapter = new HomeAdapter(mHomeModels);
        mRvType.setLayoutManager(new GridLayoutManager(activity, 4));
        mRvType.setAdapter(mHomeAdapter);
        mHomeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0://商品
                        startActivity(GoodsActivity.class);
                        break;
                    case 1://订单
                        startActivity(OrderActivity.class);
                        break;
                    case 2://日结
                        startActivity(EverydayAccountActivity.class);
                        break;
                    case 3://盘点
                        startActivity(CheckActivity.class);
                        break;
                    case 4://报表
                        startActivity(StatementActivity.class);
                        break;
                    case 5://会员
                        break;
                    case 6://促销
                        break;
                    case 7://收货
//                        startActivity(TakeDeliveryActivity.class);
                        break;
                    case 8://调货
//                        startActivity(TheCargoActivity.class);
                        break;
                    case 9://退单
//                        startActivity(ChargeBackActivity.class);
                        break;
                    case 10://退换货
                        break;
                    case 11://周边库存
                        break;
                }
            }
        });
    }

    @OnClick({R.id.tv_open_order, R.id.tv_collect_money, R.id.tv_replenishment})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_open_order://开单
                startActivity(OpenOrderActivity.class);
                break;
            case R.id.tv_collect_money://收钱
                break;
            case R.id.tv_replenishment://补货
//                startActivity(ReplenishmentActivity.class);
                break;
        }
    }
}